﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SoulDoorEngine.Components.Smart2D.Basic
{
    #region
    /// <summary>
    /// float类型向量，X表示水平方向分量，Y表示竖直方向分量
    /// </summary>
    public struct Vector
    {
        private float _X;
        private float _Y;

        /// <summary>
        /// 水平方向分量
        /// </summary>
        public float X
        {
            get { return _X; }
            set { _X = value; }
        }
        /// <summary>
        /// 竖直方向分量
        /// </summary>
        public float Y
        {
            get { return _Y; }
            set { _Y = value; }
        }
        /// <summary>
        /// 零向量
        /// </summary>
        static public Vector Zero
        {
            get { return new Vector(0f, 0f); }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="x">水平方向分量</param>
        /// <param name="y">竖直方向分量</param>
        public Vector(float x, float y)
        {
            this._X = x;
            this._Y = y;
        }

        /// <summary>
        /// 设置X
        /// </summary>
        /// <param name="x">水平方向分量</param>
        public void SetX(float x)
        {
            this.X = x;
        }

        /// <summary>
        /// 设置Y
        /// </summary>
        /// <param name="y">竖直方向分量</param>
        public void SetY(float y)
        {
            this.Y = y;
        }

        /// <summary>
        /// 重载 Vector + Vector
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator +(Vector a, Vector b)
        { return new Vector(a.X + b.X, a.Y + b.Y); }
        /// <summary>
        /// 重载 Vector - Vector
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator -(Vector a, Vector b)
        { return new Vector(a.X - b.X, a.Y - b.Y); }
        /// <summary>
        /// 重载 -Vector
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public static Vector operator -(Vector a)
        { return new Vector(-a.X, -a.Y); }
        /// <summary>
        /// 重载 Vector * float
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator *(Vector a, float b)
        { return new Vector(a.X * b, a.Y * b); }
        /// <summary>
        /// 重载 float * Vector
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator *(float a, Vector b)
        { return new Vector(b.X * a, b.Y * a); }
        /// <summary>
        /// 重载 Vector / float
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator /(Vector a, float b)
        { return new Vector(a.X / b, a.Y / b); }
        /// <summary>
        /// 重载 Vector == Vector
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool operator ==(Vector a, Vector b)
        {
            if (a.X - b.X >= -0.01 && a.X - b.X <= 0.01 && a.Y - b.Y >= -0.01 && a.Y - b.Y <= 0.01)
            { return true; }
            else
            { return false; }
        }
        /// <summary>
        /// 重载 Vector != Vector
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool operator !=(Vector a, Vector b)
        {
            if (a.X - b.X >= -0.01 && a.X - b.X <= 0.01 && a.Y - b.Y >= -0.01 && a.Y - b.Y <= 0.01)
            { return false; }
            else
            { return true; }
        }
        /// <summary>
        /// 重载 小于号
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool operator <(Vector a, Vector b)
        {
            if (a.X < b.X && a.Y < b.Y)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 重载 小于等于号
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool operator <=(Vector a, Vector b)
        {
            if (a.X <= b.X && a.Y <= b.Y)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 重载 >
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool operator >(Vector a, Vector b)
        {
            if (a.X > b.X && a.Y > b.Y)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 重载 >=
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool operator >=(Vector a, Vector b)
        {
            if (a.X >= b.X && a.Y >= b.Y)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 重载 Vector + Vector2
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator +(Vector a, Microsoft.Xna.Framework.Vector2 b)
        {
            return new Vector(a.X + b.X, a.Y + b.Y);
        }
        /// <summary>
        /// 重载 Vector2 + Vector
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator +(Microsoft.Xna.Framework.Vector2 a, Vector b)
        {
            return new Vector(a.X + b.X, a.Y + b.Y);
        }
        /// <summary>
        /// 重载 Vector - Vector2
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator -(Vector a, Microsoft.Xna.Framework.Vector2 b)
        {
            return new Vector(a.X - b.X, a.Y - b.Y);
        }
        /// <summary>
        /// 重载 Vector2 - Vector
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Vector operator -(Microsoft.Xna.Framework.Vector2 a, Vector b)
        {
            return new Vector(a.X - b.X, a.Y - b.Y);
        }

        /// <summary>
        /// 重载 Equals
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }
        /// <summary>
        /// 重载 GetHashCode
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
    #endregion
}
